#include <gflags/gflags.h>

#include "../../common/asr.h"
#include "../../common/log.h"

DEFINE_string(app_id, "6979407", "app_id");
DEFINE_string(app_key, "9p1Vp23ovppoX960l5mCShn9", "app_key");
DEFINE_string(secret_key, "txotOi5VvppAdMDdSgb72LQh8kzvwzhR", "secret_key");

DEFINE_int32(level, 1, "日志等级");
DEFINE_bool(enable_debug, false, "调试模式");
DEFINE_string(path, "", "发布模式下, 日志输出到的文件路径");

int main(int argc, char* argv[]) {
    google::ParseCommandLineFlags(&argc, &argv, true);
    initLogger(FLAGS_level, FLAGS_enable_debug, FLAGS_path);

    BaiDuYunASRClient client(FLAGS_app_id, FLAGS_app_key, FLAGS_secret_key);
    
    std::string file_content;
    client.getPcmContent("16k.pcm", &file_content);

    std::string ret = client.asr(file_content);
    if (!ret.empty()){
        LOG_INFO("{}", ret);
    } else {
        LOG_ERROR("语音识别失败");
        return -1;
    }

    return 0;
}

// #include "../../aip-cpp-sdk/speech.h"

// void asr(aip::Speech& client) {
//     std::string file_content;
//     aip::get_file_content("16k.pcm", &file_content);

//     Json::Value result = client.recognize(file_content, "pcm", 16000,
//     aip::null);

//     if (result["err_no"].isInt() == 0){
//         std::cout << "语音识别失败: " << result["err_msg"].asString() <<
//         std::endl; return;
//     }

//     std::cout << result["result"][0].asString() << std::endl;
// }

// int main() {
//     // 设置APPID/AK/SK
//     std::string app_id = "6979407";
//     std::string api_key = "9p1Vp23ovppoX960l5mCShn9";
//     std::string secret_key = "txotOi5VvppAdMDdSgb72LQh8kzvwzhR";

//     aip::Speech client(app_id, api_key, secret_key);

//     asr(client);

//     return 0;
// }